class LoadingUI extends egret.Sprite {

    private _sound: egret.Sound;
    private _channel: egret.SoundChannel;
    private volume = 0.5;
    private oWidth = 1080;
    private oHeight = 607;
    public signal = 0;
    public context: any;
    public ttq: any;
    public wrun:any;

    public progress:eui.Image;
    public progressMask:eui.Image;

    public constructor(context: any) {
        super();
        this.context = context;
        this.createView();
    }

    private textField: egret.TextField;
    private flagBetween: number = 0;
    private flagafter: number = 0;
    private imgbetween: egret.Bitmap;
    private imgafter: egret.Bitmap;
    private imgNumberlist = new Array();
    private flagNumberlist = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
    private last_number: number = 0;
    private imgArr = new Array();
    public createView(): void {
        SystemManger.RESURL
        var imgUrlArr = [SystemManger.RESURL+"assets/img/load/load_mask.png", SystemManger.RESURL+"assets/img/load/ttq_tex.png",SystemManger.RESURL+"assets/img/load/wrun1.png",SystemManger.RESURL+"assets/img/load/wrun2.png",SystemManger.RESURL+"assets/img/load/wrun3.png",SystemManger.RESURL+"assets/img/load/wrun4.png",SystemManger.RESURL+"assets/img/load/load_mask.png"];
        var point = this;
        var promiseArr = [];
        for (var i = 0; i < imgUrlArr.length; i++) {
            promiseArr.push(this.imgloadPromise(imgUrlArr[i]));
        }
        Promise.all(promiseArr).then(function () {
            point.createScene();
        });
    }

    private imgloadPromise(url) {
        var point = this;
        return new Promise(function (resolve, reject) {
            var imgLoader: egret.ImageLoader = new egret.ImageLoader;
            imgLoader.once(egret.Event.COMPLETE, imgLoadHandler, point);
            imgLoader.load(url);
            function imgLoadHandler(evt: egret.Event) {
                this.imgArr[url] = evt.currentTarget.data;
                resolve();
            }
        });
    }

    private createScene(): void {


        var bmd: egret.BitmapData = this.imgArr[SystemManger.RESURL+"assets/img/load/load_mask.png"];
        var bird: egret.Bitmap = new egret.Bitmap();
        bird.$setBitmapData(bmd);
        bird.x = 0;
        bird.y = 0;
        bird.width = this.oWidth;
        bird.height = this.oHeight;
        this.addChild(bird);


        var text: egret.TextField = this.textField = new egret.TextField();
        text.textColor = 0xffffff;
        this.addChild(text);
        text.x = 520 - text.textWidth / 2;
        text.y = 445 - text.textHeight / 2;
        text.size = 20;

        var bmd: egret.BitmapData = this.imgArr[SystemManger.RESURL+"assets/img/load/ttq_tex.png"];
        this.ttq= new egret.Bitmap();
        this.ttq.$setBitmapData(bmd);
        this.ttq.x = 210;
        this.ttq.y = 397;
        this.ttq.width = 50;
        this.ttq.height = this.ttq.width;
        this.addChild(this.ttq);
        
        this.wrun = new Wrun(this.imgArr);
        this.addChild(this.wrun);

               //音量进度条设置

    }

    public setProgress(current: number, total: number): void {
        var preNum = parseInt((current / total * 100).toString());
        if (preNum > 99) {
            preNum = 99;
        }
        this.textField.text = `${preNum}%`;
         this.ttq.x = 210+preNum*6.1;
         this.wrun.x= preNum*4.5;
        if (this.flagBetween == 1 && this.flagafter == 1) {
            this.imgbetween.width = this.oWidth * current / total * 0.834;
            this.imgafter.x = this.oWidth * current / total * 0.834 + this.oWidth * 0.074;
        }
    }
}
